﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace UnitOfWorkEF.SqlServer.Domain
{
    public interface IUnitOfWorkBaseRepository<T> where T : class
    {
        IUnitOfWork UnitOfWork { get; }

        DbSet<T> Table { get; }

        /// <summary>
        /// 异步添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        Task<T> AddAsync(T entity);

        /// <summary>
        /// 异步删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>是否成功</returns>
        Task<T> RemoveAsync(T entity);

        /// <summary>
        /// 异步修改
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>是否成功</returns>
        Task<T> UpdateAsync(T entity);

        /// <summary>
        /// 异步修改（范围）
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task UpdateRange(IEnumerable<T> entities);

        /// <summary>
        /// 异步存在
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>是否存在</returns>
        Task<bool> ExistAsync(Expression<Func<T, bool>> anyLambda);

        /// <summary>
        /// 异步查询数据
        /// </summary>
        /// <param name="whereLambda">Lamdba条件表达式</param>
        /// <returns>实体</returns>
        Task<T> FindAsync(Expression<Func<T, bool>> whereLambda);

        /// <summary>
        /// 异步查询结果集
        /// </summary>
        /// <param name="whereLamdba">Lamdba条件表达式</param>
        /// <param name="orderName">排序字段名</param>
        /// <param name="isAsc">是否升序</param>
        /// <returns>记录集</returns>
        Task<List<T>> FindRangeAsync(Expression<Func<T, bool>> whereLamdba, string orderName, bool isAsc);
        /// <summary>
        /// 异步查询分页结果集
        /// </summary>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="whereLamdba">Lamdba条件表达式</param>
        /// <param name="orderName">排序字段名</param>
        /// <param name="isAsc">是否升序</param>
        /// <returns>分页结果集,总记录数</returns>
        Task<(List<T>, int)> FindRangePageAsync(int pageIndex, int pageSize, Expression<Func<T, bool>> whereLamdba, string orderName, bool isAsc);
    }
}
